﻿using System.Collections.Generic;
using System.Xml;
namespace youdaoImport
{
    /// <summary>
    /// </summary>
    public class WordItem
    {
        public string word { get; set; }
        public string trans { get; set; }
        public string phonetic { get; set; }
        
        public static List<WordItem> getWordItems(XmlDocument doc)
        {
            List<WordItem> itemList=new List<WordItem>();
            XmlNodeList list= doc.SelectNodes("wordbook/item");
            foreach (XmlNode node in list)
            {
                WordItem item = getWordItem(node);
                if (!itemList.Exists(s => s.word.ToLower() == item.word.ToLower()))
                {
                    itemList.Add(item);
                }
            }
            return itemList;
        }
        public static WordItem getWordItem(XmlNode node)
        {
            WordItem item = new WordItem();
            var wordnode=node.SelectSingleNode("word");
            item.word = wordnode.InnerText;
            item.trans = node.SelectSingleNode("trans").InnerText;
            item.phonetic = node.SelectSingleNode("phonetic").InnerText;
            return item;
        }
    }
}
